package com.easyctrl.adapter;

import java.util.ArrayList;

import com.easyctrl.ldy.activity.R;

import android.R.string;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class VirtualMLIstAdapter extends BaseAdapter{

	private static VirtualMLIstAdapter adapter;
	private ArrayList<String> beans;
	private LayoutInflater mInflater;
	private VirtualMLIstAdapter(Context context,ArrayList<String> beans){ 
		this.mInflater = LayoutInflater.from(context);
		this.beans = beans;
	}
	
	public static VirtualMLIstAdapter getAdapter(Context context,ArrayList<String> beans){
		if(adapter == null){
			adapter = new VirtualMLIstAdapter(context, beans);
		}
		return adapter;
	}
	
	@Override
	public int getCount() {
		return beans == null ? 0 : beans.size();
	}

	@Override
	public Object getItem(int position) { 
		return beans.get(position);
	}

	@Override
	public long getItemId(int position) { 
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		String type = beans.get(position);
		ViewHolder holder;
		if(convertView == null){
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.virtual_string_type_item, parent,false);
			holder.strType = (TextView) convertView.findViewById(R.id.strType);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		holder.strType.setText(sprit(type));
		return convertView;
	}
	
	private String sprit(String type){
		Integer arr = Integer.valueOf(type);
		
		int start = arr * 10 + 1;
		int end = start + 9;
		
		String result = String.valueOf(start) +" ~ " + String.valueOf(end);
		
		return result;
	}
	
	public class ViewHolder{
		public TextView strType;
	}

}
